package com.qf.forumproject.blog.controller;

import com.qf.forumproject.entity.QfBlog;
import com.qf.forumproject.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.qf.forumproject.entity.QfBlogCategory;
import com.qf.forumproject.blog.service.QfBlogCategoryService;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QfBlogCategory)控制层
 *
 * @author protagonist
 * @since 2022-07-23 11:42:23
 */
@RestController
@Slf4j
@RequestMapping("/BlogCategory")
@Api(tags = "博客分类接口")
public class QfBlogCategoryController {
    /**
     * 服务对象
     */
    @Resource
    private QfBlogCategoryService qfBlogCategoryServiceImpl;

    /**
     * 查询所有博客文章的分类（不需要分页查询）
     * @return Result对象
     *//*
    @GetMapping(value = "/selectAll")
    @ApiOperation("查询所有博客分类")
    public Result<List<QfBlogCategory>> selectAll(){
        List<QfBlogCategory> qfBlogCategorys = qfBlogCategoryServiceImpl.selectAll();
        if (CollectionUtils.isEmpty(qfBlogCategorys)) {
            return new Result<>(true, StatusCode.ERROR, "博客分类查询失败");
        }
        return new Result<>(true, StatusCode.OK, "博客分类查询成功", qfBlogCategorys);
    }*/


    /**
     * 查询所有博客文章的分类（不需要分页查询）
     * @return Result对象
     */
    @GetMapping(value = "/selectAll")
    @ApiOperation("查询所有博客分类")
    public Result<List<QfBlogCategory>> selectAll(){
        List<QfBlogCategory> blogCategoryList = qfBlogCategoryServiceImpl.list();
        if (CollectionUtils.isEmpty(blogCategoryList)) {
            return new Result<>(false, StatusCode.ERROR, "博客分类查询失败");
        }
        return new Result<>(true, StatusCode.OK, "博客分类查询成功", blogCategoryList);
    }


    /**
     * 根据博客分类的id到博客表中分页查询该类的所有文章
     * @param blogSearchVo
     * @return
     */
    @GetMapping("/getByConditions")
    @ApiOperation("查询分类下的文章")
    public Result getPassageByConditions(SearchVo blogSearchVo){

        //PageInit.initPage(blogSearchVo);

        List<ResultVo> blogs = qfBlogCategoryServiceImpl.selectByBlogCategoryId(blogSearchVo);

        if (CollectionUtils.isEmpty(blogs)) {
            return new Result<>(false, StatusCode.ERROR, "按id查询文章失败");
        }
        return new Result<>(true, StatusCode.OK, "按id查询文章成功", blogs);
    }
}
